<?php
/**
 ** added by lss@2017/07/14
 ** 定时删除数据表pk10_referral_guess_new 中3天前的数据
**/

//die('already done');

set_time_limit(0);
date_default_timezone_set("PRC");
include('./db_config.php');

//1.连接数据库->pdo方式
$db_pdo_link = pdo_write_read_link();


$start_date = strtotime("now")-3600*24*3;
$start_time = date('Y-m-d H:i:s',$start_date);
$guess_count_sql = "select count(*)  as count from  pk10_referral_guess_new where addtime<='{$start_time}'";
$guess_count_res = $db_pdo_link->query($guess_count_sql);
$guess_count_array = $guess_count_res->fetch(PDO::FETCH_ASSOC);
$count = $guess_count_array['count'];
if($count <= 0 )
{
	die('no need to run below');
}

$for_i  = floor($count/10000);
for($i=1;$i<=$for_i;$i++)
{
	$guess_id_array = array();
	$get_guess_id_sql = "select  guess_id  from pk10_referral_guess_new  where addtime<='{$start_time}' order by addtime asc limit 10000";
	$get_guess_id_res = $db_pdo_link->query($get_guess_id_sql);
	$get_guess_id_result = $get_guess_id_res->fetchAll(PDO::FETCH_ASSOC);
	foreach($get_guess_id_result as $guess_id_single)
	{
		$guess_id_array[] = $guess_id_single['guess_id'];
	}
	$guess_ids = implode(',',$guess_id_array);
	$del_sql  = "delete from pk10_referral_guess_new where guess_id in($guess_ids)";
	$del_result = $db_pdo_link->exec($del_sql);
	$content = date('y-m-d h:i:s').'=>del datas : '.$del_result;
	file_put_contents('del_record.txt',$content.'\rn',LOCK_EX|FILE_APPEND);
}









?>
